package br.ufg.inf.espweb.sgca.dao.impl;

import br.ufg.inf.espweb.sgca.dao.DocenteDao;
import br.ufg.inf.espweb.sgca.model.Docente;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author diCastro
 */
@Repository
@Transactional(propagation = Propagation.REQUIRED)
public class DocenteDaoImpl extends GenericDaoImpl<Docente> implements DocenteDao{
    
    @PersistenceContext
    private EntityManager entityManager;
    
    @Override
    protected EntityManager getEntityManager() {
        return entityManager;
    }

    @Override
    protected Class<Docente> getEntityClass() {
        return Docente.class;
    }

    @Override
    public Docente buscarDocentePeloNomeCompleto(String nome) {
        Criteria criteria = getSession().createCriteria(Docente.class);
        criteria.add(Restrictions.eq("nomeCompleto", nome));
        criteria.setMaxResults(1);
        return (Docente) criteria.uniqueResult();
    }
    
}
